
package com.nextel.ui.custom; // Generated package name
import com.nextel.ui.*;
import com.nextel.util.Debug;
import com.nextel.util.lwuit.Font;
import javax.microedition.lcdui.Canvas;
import com.nextel.util.Logger;


public class OTextFieldDecimal
        extends OBoxtField implements OTextDecimalListener {

     private  char simbolo = '.';

    public boolean isPermitirMasDecimal = false;

    public OTextFieldDecimal(int nbrOfChars, Font font) {
        super(nbrOfChars, font, OBoxtField.NUMERIC);

    }

   public OTextFieldDecimal(int nbrOfChars, Font font, char simbolo) {
        super(nbrOfChars, font, OBoxtField.NUMERIC);
        this.simbolo =  simbolo;

    }

    public OTextFieldDecimal(int nbrOfChars, Font font, int Constraint) {
        super(nbrOfChars, font, Constraint);
    }

    public OTextFieldDecimal(int nbrOfChars, Font font, int Constraint, char simbolo) {
        super(nbrOfChars, font, Constraint);
        this.simbolo = simbolo;
    }
    
    public void keyRepeated(int key) {
//        System.out.println("OTextFieldDecimal.keyRepeated" + key);
        if (key == Canvas.KEY_NUM1) {

            if (isPermitirMasDecimal) {
                keyPressed(Canvas.KEY_STAR);
               // composer.document.insertChar('.');
                composer.document.insertChar(simbolo);
                repaint();
            } else {
                //if (composer.document.getText().indexOf('.') == -1) {
                //System.out.println("composer.document.getText()= "+composer.document.getText());
                // El get ya realiza la conversion al punto
                if (composer.document.getText().indexOf('.') == -1) {
                    keyPressed(Canvas.KEY_STAR);
                 //   composer.document.insertChar('.');
                    composer.document.insertChar(simbolo);
                    repaint();
                }
            }
        }
    }
    
    public void setText(String value) //    throws InvalidData
    {
        
        value = value.replace('.', simbolo);
        
        if (value.length() > 0) {
            //  validate( value ); // throws exception if invalid
            textBuff = new StringBuffer(value);
            textBuff.ensureCapacity(nbrOfChars);
        } else {
            textBuff = new StringBuffer(nbrOfChars);
        }
        cursorIdx = 0;
        
        repaint();
        
        if (Debug.ON) {
            Logger.dev("OTextField.setText EXITTING");
        }
    } // setText
    
    /**
     * Gets the text that is in the field.
     *
     * @return The text in the field
     */
    
    public String getText() {
        if (Debug.ON) {
            Logger.dev("OTextField.getText ENTERED");
        }
        return textBuff.toString().replace(simbolo, '.');
    } // getText
}

  
